package com.sc.nft.hna.form;

import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.sc.nft.config.hna.HnaConfig;
import com.sc.nft.dto.HnaFastPayConfirmDTO;
import com.sc.nft.mapstruct.HnaMapStruct;
import lombok.Data;

import java.util.Map;

@Data
public class T008TransForm extends BaseTransForm {

  public static final String[] encryptArr =
      new String[] {
        "ncountOrderId",
        "smsCode",
        "merUserIp",
        "paymentTerminalInfo",
        "receiverTerminalInfo",
        "deviceInfo",
        "businessType",
        "feeType",
        "divideAcctDtl",
        "feeAmountUser"
      };
  public static final String[] verifyArr =
      new String[] {
        "version",
        "tranCode",
        "merOrderId",
        "merId",
        "charset",
        "signType",
        "resultCode",
        "errorCode",
        "ncountOrderId",
        "tranAmount",
        "checkDate",
        "submitTime",
        "tranFinishTime",
        "bankCode",
        "cardType",
        "shortCardNo",
        "bindCardAgrNo"
      };
  public static final String[] notifyVerifyArr = verifyArr;
  public static final String[] submitArr =
      new String[] {
        "version",
        "tranCode",
        "merId",
        "merOrderId",
        "submitTime",
        "msgCiphertext",
        "signType",
        "signValue",
        "merAttach",
        "charset"
      };
  private static final long serialVersionUID = 8083424349847655973L;

  private String ncountOrderId; // 新账通订单号
  private String smsCode; // 短信验证码
  private String merUserIp; // 商户用户IP
  private String paymentTerminalInfo; // 付款方终端信息
  private String receiverTerminalInfo; // 收款方终端信息
  private String deviceInfo; // 设备信息
  private String businessType; // 业务类型
  private String feeType; // 手续费内扣外扣
  private String divideAcctDtl; // 分账明细
  private String feeAmountUser; // 手续费承担方id

  public static final String MAIN_URL = "https://ncount.hnapay.com/api/t008.htm";
  public static final String TRAN_CODE = "T008";

  @Override
  public String getEncryptJsonStr() {
    return getJsonStr(this, encryptArr);
  }

  @Override
  public String getVerifyJsonStr() {
    return getJsonStr(this, verifyArr);
  }

  @Override
  public String getSubmitJsonStr() {
    return getJsonStr(this, submitArr);
  }

  public static Map<String, Object> generateParam(HnaConfig hnaConfig, HnaFastPayConfirmDTO dto) {
    T008TransForm transForm = HnaMapStruct.INSTANCE.dto2t008form(dto);
    transForm.initCommonParams(
        TRAN_CODE, hnaConfig.getMerId(), IdWorker.getIdStr(), dto.getMerAttach());
    return generateParam(transForm, hnaConfig);
  }
}
